home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Skeleton / UApplicationSkeleton.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  5.0 KB  |  135 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // USkeletonApplication.cp
  3. // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved. 
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UAPPLICATIONSKELETON__
  7. #include "UApplicationSkeleton.h"
  8. #endif
  9.  
  10. #ifndef __UDOCUMENTSKELETON__
  11. #include "UDocumentSkeleton.h"
  12. #endif
  13.  
  14. #ifndef __UVIEWSKELETON__
  15. #include "UViewSkeleton.h"
  16. #endif
  17.  
  18. #ifndef __UMENUMGR__
  19. #include "UMenuMgr.h"
  20. #endif
  21.  
  22. //----------------------------------------------------------------------------------------
  23. // Constants:
  24.  
  25. const OSType kSignature            = 'SS01';            // Application signature
  26.         
  27. const CommandNumber cCommandHandledByApplication =    400;
  28.  
  29. //========================================================================================
  30. // CLASS TApplicationSkeleton
  31. //========================================================================================
  32. #undef Inherited
  33. #define Inherited TApplication
  34.  
  35. #pragma segment AInit
  36. MA_DEFINE_CLASS_M1(TApplicationSkeleton, Inherited);
  37.  
  38. //----------------------------------------------------------------------------------------
  39. // TApplicationSkeleton constructor
  40. //----------------------------------------------------------------------------------------
  41. #pragma segment AOpen
  42.  
  43. TApplicationSkeleton::TApplicationSkeleton()
  44. {
  45.     // Initialize fields to safe values here
  46. }
  47.  
  48. //----------------------------------------------------------------------------------------
  49. // TApplicationSkeleton destructor
  50. //----------------------------------------------------------------------------------------
  51. #pragma segment MADestructorRes
  52.  
  53. TApplicationSkeleton::~TApplicationSkeleton()
  54. {
  55. }
  56.  
  57. //----------------------------------------------------------------------------------------
  58. // TApplicationSkeleton::IApplicationSkeleton: 
  59. //----------------------------------------------------------------------------------------
  60. #pragma segment AInit
  61.  
  62. void TApplicationSkeleton::IApplicationSkeleton()
  63. {
  64.     this->IApplication(kFileType,kSignature);
  65. } // TApplicationSkeleton::IApplicationSkeleton 
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // TApplicationSkeleton::DoMakeDocument: This method is overridden to return a document
  69. // object of the appropriate class for this application. MacApp calls this method when the
  70. // user chooose New or Open from the File menu. For applications which hande multiple
  71. // document types, the command number can be used to discriminate between different user
  72. // requests. The file object represents the file chosen by the user in the Standard File
  73. // dialog.
  74. //----------------------------------------------------------------------------------------
  75. #pragma segment AOpen
  76.             
  77. TDocument* TApplicationSkeleton::DoMakeDocument(CommandNumber /* itsCommandNumber */,
  78.                                                         TFile* itsFile) // Override 
  79. {
  80.     TDocumentSkeleton* aDocument = new TDocumentSkeleton;
  81.     
  82.     aDocument->IDocumentSkeleton(itsFile,kSignature);
  83.     return aDocument;
  84. } // TApplicationSkeleton::DoMakeDocument 
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // TApplicationSkeleton::DoMenuCommand: This method is overridden to handle menu items
  88. // which are enabled when this object is in the target chain. The application object is
  89. // always in the target chain.
  90. // 
  91. // The inherited method is called so that MacApp can handle application-level menu items
  92. // like the "About " menu item in the Apple menu.
  93. //----------------------------------------------------------------------------------------
  94. #pragma segment ASelCommand
  95.  
  96. void TApplicationSkeleton::DoMenuCommand(CommandNumber aCommandNumber) // Override 
  97. {
  98.     switch (aCommandNumber) 
  99.     {
  100.         case cCommandHandledByApplication : 
  101.             SysBeep(2);
  102.             break;
  103.         default:
  104.             Inherited::DoMenuCommand(aCommandNumber);
  105.             break;
  106.     }
  107. } // TApplicationSkeleton::DoMenuCommand 
  108.  
  109. //----------------------------------------------------------------------------------------
  110. // TApplicationSkeleton::DoSetupMenus: This method is overridden to enable menu items
  111. // which should be enabled when this object is in the target chain. MacApp initially
  112. // disables all menu items, then lets the objects in the target chain enable those items
  113. // they handle.
  114. //
  115. // The application object is always in the target chain, so the About menu item in the
  116. // Apple menu and the item with command number cMenuHandledByApplication should be enabled
  117. // even if there are no open documents.
  118. // 
  119. // The inherited method is called so that MacApp can enable application-level menu items
  120. // like the "About " menu item.
  121. //----------------------------------------------------------------------------------------
  122. #pragma segment ARes
  123.  
  124. void TApplicationSkeleton::DoSetupMenus() // Override 
  125. {
  126.     Inherited::DoSetupMenus();                // Always call the inherited method first
  127.  
  128.     Enable(cCommandHandledByApplication,TRUE);
  129. } // TApplicationSkeleton::DoSetupMenus 
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // End of UApplicationSkeleton.cp
  133.  
  134. #pragma segment Inline
  135.